﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameEngine.Entities;
using Microsoft.Xna.Framework;

namespace GameEngine.EntityComponents
{
    public class EnemyComponent : IEntityComponent
    {
        AbstractEntity entity;
        Dictionary<String, float> weapons = new Dictionary<String, float>();

        /// <summary>
        /// Initializes a new instance of the <see cref="EnemyComponent" /> class.
        /// </summary>
        /// <param name="entity">The entity.</param>
        public EnemyComponent(AbstractEntity entity)
        {
            this.entity = entity;
            this.weapons.Add("Touch of Death", 5f);
            //this.weapons.Add("Projectile", 0.2f);
        }

        public void Update(GameTime gameTime)
        { }

        /// <summary>
        /// This method decides what to do if a collision occurs with this component
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="isX">if set to <c>true</c> [is X].</param>
        /// <param name="isY">if set to <c>true</c> [is Y].</param>
        public void CollideWith(AbstractEntity target, bool isX, bool isY)
        {
            TerminateableComponent targetComponent = (TerminateableComponent)target.GetComponent(typeof(TerminateableComponent));
            if (targetComponent != null)
                targetComponent.DealDamage(CalcDamage(this.entity));
        }

        /// <summary>
        /// Calcs the damage.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <returns></returns>
        public float CalcDamage(AbstractEntity target)
        {
            return weapons.First().Value;
        }

        /// <summary>
        /// Adds a weapon.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="value">The value.</param>
        public void AddWeapon(String name, float value) {
            this.weapons.Add(name, value);
        }

        /// <summary>
        /// Removes a weapon.
        /// </summary>
        /// <param name="name">The name.</param>
        public void RemoveWeapon(String name) {
            this.weapons.Remove(name);
        }
    }
}
